package com.EM1.www.servlet;

import com.EM1.www.dao.ConnectGrade;
import com.EM1.www.po.Teacher;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/Bandgrade")
public class Bandgrade extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String bandgrade = request.getParameter("bandgrade");
        HttpSession session = request.getSession();
        Teacher teacher = (Teacher) session.getAttribute("teacher");
        ConnectGrade connectGrade=new ConnectGrade();
        try {
            connectGrade.insertGrade(teacher.getId(),Integer.parseInt(bandgrade));
            ArrayList<Integer> grade = teacher.getGrade();
            grade.add(Integer.parseInt(bandgrade));
            session.setAttribute("teacher",teacher);
            request.getRequestDispatcher("teacher.jsp").forward(request,response);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
